import core.*;
import core.designpattern.observer.*;
import corejuliano.*;
import corejuliano.designpattern.observer.*;

import util.file.*;
import util.*;

class util.file.XMLParser extends Observable
{
	private var xml:XML;
	
	private var loaded:Boolean = false;
	private var fileName:String;
	
	public function XMLParser(fileName:String , path:String)
	{
		this.fileName = fileName;
		
		var loadVars:LoadVars = new LoadVars();//versao 7,8
		Logger.trace("Lendo arquivo em " + path + fileName + ".xml");
		loadVars.sendAndLoad(path + fileName + ".xml", this);
	}
	
	public function getFileName():String
	{
		return fileName;
	}

	public function onData(data:String):Void
	{
		xml = new XML();
		xml.ignoreWhite = true;
		xml.parseXML(data);

		mountStruct();
	
		loaded = true;

		warningObservers();
	}
	
	public function warningObservers():Void
	{
		for (var i:Number = 0; i < observers.length; i++)
			XMLParserObserver( observers[i] ).onLoadDataXMLParser(this);
	}
	
	public function addObserver(observer:XMLParserObserver):Void
	{
		super.addObserver(observer);
	}
	
	public function getXML():XML
	{
		return xml;
	}
	
	public function isLoaded():Boolean
	{
		return loaded;
	}
	
	public function toString():String
	{
		return "core.util.XMLParser";
	}
	
	/**
	* metodo que deve ser sobrescrito para montar estrutura especifica
	*/
	private function mountStruct():Void{}
	
}